export function isInBBox(point, bbox) {
  const {
      x,
      y
    } = point;
    const {
      minX,
      minY,
      maxX,
      maxY
    } = bbox;
  
    return x < maxX && x > minX && y > minY && y < maxY;
} 

/**
* format the string
* @param {string} str The origin string
* @param {number} maxWidth max width
* @param {number} fontSize font size
* @return {string} the processed result
*/
import G6 from '@antv/g6';

export function fittingString(str, maxWidth, fontSize) {
const ellipsis = '...';
const ellipsisLength = G6.Util.getTextSize(ellipsis, fontSize)[0];
let currentWidth = 0;
let res = str;
const pattern = new RegExp('[\u4E00-\u9FA5]+'); // distinguish the Chinese charactors and letters
str.split('').forEach((letter, i) => {
  if (currentWidth > maxWidth - ellipsisLength) return;
  if (pattern.test(letter)) {
    // Chinese charactors
    currentWidth += fontSize;
  } else {
    // get the width of single letter according to the fontSize
    currentWidth += G6.Util.getLetterWidth(letter, fontSize);
  }
  if (currentWidth > maxWidth - ellipsisLength) {
    res = `${str.substr(0, i)}${ellipsis}`;
  }
});
return res;
};